package com.study.concurrent.B_ThreadSynchronizedBasic.c_UseIndependentAttributes;

/**
 * Created by 赵超 on 2017/3/22.
 */
public class Main {
    public static void main(String[] args) {
        /**
         * 声明电影院对象
         */
        Cinema cinema = new Cinema(20, 20);

        /**
         * 创建售票处一 并用它创建线程
         */
        TicketOffice1 ticketOffice1 = new TicketOffice1(cinema);
        Thread thread1 = new Thread(ticketOffice1);

        /**
         * 创建售票处二 并用它创建线程
         */
        TicketOffice2 ticketOffice2 = new TicketOffice2(cinema);
        Thread thread2 = new Thread(ticketOffice2);

        /**
         * 启动线程
         */
        thread1.start();
        thread2.start();

        /**
         * 等待两个线程结束
         */
        try {
            thread1.join();
            thread2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        /**
         * 打印两个电影院的剩余票数量
         */
        System.out.printf("电影院一剩余 %s 张票\n", cinema.getVacanciesCinema1());
        System.out.printf("电影院二剩余 %s 张票\n", cinema.getVacanciesCinema2());
    }
}
